﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
using Microsoft.Phone.Tasks;
using CommonControls.ClassFiles;

namespace CommonControls.AboutApps
{
    public class PhoneHelper
    {
        private const string AppManifestName = "WMAppManifest.xml";
        private const string AppNodeName = "App";
        public static string GetAppAttribute(string attributeName)
        {
            string attribute;
            try
            {
                XmlReaderSettings settings2 = new XmlReaderSettings
                {
                    XmlResolver = new XmlXapResolver()
                };
                XmlReaderSettings settings = settings2;
                using (XmlReader reader = XmlReader.Create("WMAppManifest.xml", settings))
                {
                    reader.ReadToDescendant("App");
                    if (!reader.IsStartElement())
                    {
                        throw new FormatException("WMAppManifest.xml is missing App");
                    }
                    attribute = reader.GetAttribute(attributeName);
                }
            }
            catch (Exception)
            {
                attribute = "";
            }
            return attribute;
        }

        public static void LoadYoutubeVideo(string url)
        {
            try
            {
                string AppLink = "vnd.youtube:" + url + "?vndapp=youtube_mobile&vndclient=mv-google&vndel=watch";
                WebBrowserTask webBrowserTask = new WebBrowserTask();
                webBrowserTask.URL = AppLink;
                webBrowserTask.Show();
            }
            catch (Exception ex)
            {
                string status = IsolatedSettings.getStringValue("SendErrors");
                if (status == "true")
                {
                    string mess = "Exception in LoadYoutubeVideo Method In PhoneHelper.cs file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                   Exceptions.SaveOrSendExceptions(mess, ex.Data);
                }
            }


        }
    }
}
